package com.sc.study.sleeproom.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.sc.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sc.study.sleeproom.mapper.ScSleepRoomMapper;
import com.sc.study.sleeproom.domain.ScSleepRoom;
import com.sc.study.sleeproom.service.IScSleepRoomService;

/**
 * 寝室Service业务层处理
 * 
 * @author sc
 * @date 2022-03-14
 */
@Service
public class ScSleepRoomServiceImpl implements IScSleepRoomService 
{
    @Autowired
    private ScSleepRoomMapper scSleepRoomMapper;

    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 查询寝室
     * 
     * @param id 寝室主键
     * @return 寝室
     */
    @Override
    public ScSleepRoom selectScSleepRoomById(Long id)
    {
        return scSleepRoomMapper.selectScSleepRoomById(id);
    }

    /**
     * 查询寝室列表
     * 
     * @param scSleepRoom 寝室
     * @return 寝室
     */
    @Override
    public List<ScSleepRoom> selectScSleepRoomList(ScSleepRoom scSleepRoom)
    {
        return scSleepRoomMapper.selectScSleepRoomList(scSleepRoom);
    }

    /**
     * 新增寝室
     * 
     * @param scSleepRoom 寝室
     * @return 结果
     */
    @Override
    public int insertScSleepRoom(ScSleepRoom scSleepRoom)
    {
        return scSleepRoomMapper.insertScSleepRoom(scSleepRoom);
    }

    /**
     * 修改寝室
     * 
     * @param scSleepRoom 寝室
     * @return 结果
     */
    @Override
    public int updateScSleepRoom(ScSleepRoom scSleepRoom)
    {
        return scSleepRoomMapper.updateScSleepRoom(scSleepRoom);
    }

    /**
     * 批量删除寝室
     * 
     * @param ids 需要删除的寝室主键
     * @return 结果
     */
    @Override
    public int deleteScSleepRoomByIds(Long[] ids)
    {
        return scSleepRoomMapper.deleteScSleepRoomByIds(ids);
    }

    /**
     * 删除寝室信息
     * 
     * @param id 寝室主键
     * @return 结果
     */
    @Override
    public int deleteScSleepRoomById(Long id)
    {
        return scSleepRoomMapper.deleteScSleepRoomById(id);
    }

    /**
     * 获取当前班级 管理的寝室
     * zwt
     * @param clazzId
     * @param sex
     */
    @Override
    public List<ScSleepRoom> getClazzForRooms(Integer clazzId, String sex) {
        List<Long> sleep_room_person_type_stu = JSON.parseArray(sysConfigService.selectConfigByKey("sleep_room_person_type_stu"), Long.class);
        return scSleepRoomMapper.getClazzForRooms(clazzId, sex, sleep_room_person_type_stu);
    }

    /**
     * 查询所有寝室不分页
     * zwt
     * @param sleepRoomName   栋 + 层 + 名称 模糊查询
     * @param sex
     * @return
     */
    @Override
    public List<ScSleepRoom> getSleepRoomList(String sleepRoomName, String sex){
        return scSleepRoomMapper.getSleepRoomList(sleepRoomName, sex);
    }
}
